package net.maku.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import net.maku.bean.query.WebPayConfigQuery;
import net.maku.bean.vo.WebPayConfigVO;
import net.maku.convert.WebPayConfigConvert;
import net.maku.entity.WebPayConfigEntity;
import net.maku.mapper.WebPayConfigMapper;
import net.maku.utils.PageResult;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 支付配置表
 *
 * @author 阿沐 babamu@126.com
 * @since 1.0.0 2024-09-06
 */
@Service
@AllArgsConstructor
//public class WebPayConfigServiceImpl extends BaseServiceImpl<WebPayConfigDao, WebPayConfigEntity> implements WebPayConfigService {
public class WebPayConfigServiceImpl extends BaseServiceImpl<WebPayConfigMapper, WebPayConfigEntity> implements IService<WebPayConfigEntity> {

    public PageResult<WebPayConfigVO> page(WebPayConfigQuery query) {
        IPage<WebPayConfigEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));

        return new PageResult<>(WebPayConfigConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
    }

    private LambdaQueryWrapper<WebPayConfigEntity> getWrapper(WebPayConfigQuery query){
        LambdaQueryWrapper<WebPayConfigEntity> wrapper = Wrappers.lambdaQuery();
        return wrapper;
    }

    public void save(WebPayConfigVO vo) {
        WebPayConfigEntity entity = WebPayConfigConvert.INSTANCE.convert(vo);

        baseMapper.insert(entity);
    }

    public void update(WebPayConfigVO vo) {
        WebPayConfigEntity entity = WebPayConfigConvert.INSTANCE.convert(vo);

        updateById(entity);
    }

    @Transactional(rollbackFor = Exception.class)
    public void delete(List<Long> idList) {
        removeByIds(idList);
    }

}